<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="{{__PUBLIC__}}/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="{{__PUBLIC__}}/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link rel="stylesheet" href="{{__PUBLIC__}}/bootstrap-3.3.5-dist/css/bootstrap.min.css" />
	    <link rel="stylesheet" type="text/css" href="{{__PUBLIC__}}/Admin/css/type_attr.css"/>
	    <script type="text/javascript" src="{{__PUBLIC__}}/jquery-1.7.2.min.js"></script>
	    <script type="text/javascript" src="{{__PUBLIC__}}/uploadify/jquery.uploadify.min.js"></script>
	    <script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="{{__PUBLIC__}}/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
     	<link rel="stylesheet" type="text/css" href="{{__PUBLIC__}}/uploadify/uploadify.css">
	    <script type="text/javascript">
	    $(function(){
	    	$('select[name=category_cid]').change(function(){
	    		//获取被选中的category_cid
	    		var type_tid = $(':selected',this).attr('type_tid');
	    		//通过异步发送type_tid,
	    		//获得类型的属性，然后组合字符串插入到页面
	    		$.ajax({
	    			//请求地址
	    			url:"{{U('ajaxGetAttr')}}",
	    			//发送数据
	    			data:{type_tid:type_tid},
	    			//请求类型
	    			type:'post',
	    			//返回的数据类型
	    			dataType:'json',
	    			//成功返回
	    			success:function(phpData){
	    				//属性
	    				var attr= '';
	    				//规格
	    				var spec = '';
	    				$.each(phpData,function(k,v){
	    					//如果是属性
	    					if(v.class==1){
	    						attr +='<tr class="active"><td>'+v.taname+'</td><td>';
	    						attr +='<select class="form-control" name="attr['+v.taid+']"><option value="">请选择</option>';
	    							$.each(v.tavalue,function(kk,vv){
	    								attr +='<option value="'+vv+'">'+vv+'</option>';
	    							});
	    						attr += '</select></td><input type="hidden" name="type_tid" value="'+v.type_tid+'"></tr>';
	    					}else{
	    						spec += '<tr class="active"><td>'+v.taname+'</td><td>';
	    						spec += '<select class="form-control" name="spec['+v.taid+'][value][]"><option value="">请选择</option>';
	    							$.each(v.tavalue,function(kk,vv){
	    								spec +='<option value="'+vv+'">'+vv+'</option>';
	    							});
	    							spec +='</select></td>';
	    							spec +='<td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" value="0" /></td>';
	    							spec += '<td><span class="add-spec btn btn-success">添加规格</span>&nbsp;&nbsp;<span class="btn btn-danger del-spec">删除规格</span></td>';
	    							spec += '<input type="hidden" name="type_tid" value="'+v.type_tid+'"></tr>';
	    					}
	    				});
						$('#att').html(attr);
						$('#spe').html(spec);
	    			}
	    		})
	    	})
			//点击增加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var tr = $(this).parents('tr');
				//克隆tr
				var trObj = tr.clone();
				tr.after(trObj);
			})
			//删除规格
			$('.del-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
			//删除图片
			$('.dell').live('click',function(){
				$(this).parents('li').remove();
			})
	    })
	    </script>
	</head>
	<body>
		<div>
		<form action="" method="post">	
			<span class="btn btn-info">基本信息</span>
			<table class="table table-hover">
				<tr class="active">
					<td>所属分类</td>
					<td>
						<select class="form-control" name="category_cid">
								<option value="0">-请选择-</option>
							{{foreach from="$cateData" value="$v"}}
								<option value="{{$v['cid']}}" {{if value="$v['cid'] eq $data['category_cid']"}} selected {{endif}} type_tid ="{{$v['type_tid']}}">{{$v['_name']}}
								</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
				<tr class="active">
					<td>所属品牌</td>
					<td>
						<select class="form-control" name="brand_bid">
							<option value="0">-请选择-</option>
							{{foreach from="$brand" value="$v"}}
							<option value="{{$v['bid']}}" {{if value="$v['bid'] eq $data['brand_bid']"}} selected {{endif}}>{{$v['bname']}}</option>
							{{endforeach}}
						</select>
					</td>
				</tr>
				<tr class="success">
					<td>商品名称</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商品名称"  name="gname" value="{{$data['gname']}}">
					</td>
				</tr>
				<tr class="success">
					<td>单位</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" value="{{$data['unit']}}" name="unit">
					</td>
				</tr>
				<tr class="active">
					<td>市价场</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入市场价"  name="market_price" value="{{$data['market_price']}}">
					</td>
				</tr>
				<tr class="info">
					<td>商城价</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商城价"  name="shop_price" value="{{$data['shop_price']}}">
					</td>
				</tr>
				<tr class="info">
					<td>库存</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入库存量"  name="inventory" value="{{$data['inventory']}}">
					</td>
				</tr>
				<tr class="success">
					<td>点击次数</td>
					<td>
						<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入点击次数" value="{{$data['click']}}"  name="click">
					</td>
				</tr>
			</table>
			<p class="btn btn-info">商品属性</p>
			<table class="table table-hover" id="att">
				{{foreach from="$gdata" value="$v"}}
				<tr class="active">
					<td>{{$v['taname']}}</td>
					<td>
						<select class="form-control" name="attr[{{$v['type_attribute_taid']}}]">
							{{foreach from="$v['tavalue']" value="$t"}}
								<option value="{{$v['gavalue']}}" {{if value="$v['gavalue'] eq $t"}} selected {{endif}}>{{$t}}</option>
							{{endforeach}}
						</select>
					</td>
					<input type="hidden" name="type_tid" value="{{$v['type_tid']}}">
				</tr>
				{{endforeach}}
			</table>
			<p class="btn btn-info">商品规格</p>
			<table class="table table-hover" id="spe">
				{{foreach from="$gdata2" value="$v2"}}
				<tr class="active">
					<td>{{$v2['taname']}}</td>
					<td>
		    			<select class="form-control" name="spec[{{$v2['type_attribute_taid']}}][value][]">
		    				{{foreach from="$v2['tavalue']" value="$t2"}}
		    					<option value="{{$t2}}" {{if value="$v2['gavalue'] eq $t2"}} selected {{endif}}>{{$t2}}</option>
							{{endforeach}}
						</select>
					</td>
		    		<td>附加价格：<input type="text" name="spec[{{$v2['type_attribute_taid']}}][price][]" value="{{$v2['value_added']}}" />
		    		</td>
		    		<td>
		    			<span class="add-spec btn btn-success">添加规格</span>&nbsp;&nbsp;<span class="btn btn-danger del-spec">删除规格</span>
		    		</td>
		    		<input type="hidden" name="type_tid" value="{{$v2['type_tid']}}">
	    		</tr>
	    		{{endforeach}}
			</table>

			<span class="btn btn-info">列表图</span>
			<div lab="uploadFile">
			<table class='table table-bordered'>
				<tr class="info">
					<td>上传图片</td>
					<td>
		                <input id="file" type="file" multiple="true">
		                <span>类型: *.jpg,*.png,*.gif 大小: 2000KB 数量: 1</span>
		                <script type="text/javascript">
		                    $(function() {
		                        $('#file').uploadify({
		                            'formData'     : {//POST数据
		                                '<?php echo session_name();?>' : '<?php echo session_id();?>',
		                            },
		                            'fileTypeDesc' : '上传文件',//上传描述
		                            'fileTypeExts' : '*.jpg;*.png;*.gif',//上传允许的类型
		                            'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',//上传的flash
		                            'uploader' : '{{U('upload')}}',//上传调用的方法
		                            'buttonText':'选择文件',
		                            'fileSizeLimit' : '2000KB',//上传文件的大小
		                            'uploadLimit' : 10,//上传文件数
		                            'width':65,
		                            'height':25,
		                            'successTimeout':10,//等待服务器响应时间
		                            'removeTimeout' : 0.2,//成功显示时间
		                            'onUploadSuccess' : function(file, data, response) {
		                                //转为json
		                                data=$.parseJSON(data);
		                                //获得图片地址
		                                $("#img_1").attr("src",data);
		                                $("input[name=list_view]").attr("value",data);
		                            }
		                        });
		                    });
		                </script>
					</td>
				</tr>
			</table>
			<!-- 异步上传后图片显示的位置 -->
                <div id="uploadList" width="100">
                    <ul>
						<li><img src="{{$data['list_view']}}" id="img_1" alt="">
						<input type="hidden" value="{{$data['list_view']}}" name="list_view">
						</li>
                    </ul>
                </div>
			</div>
			<span class="btn btn-info">商品图册</span>
			<div lab="uploadFile">
			<table class='table table-bordered'>
				<tr class="info">
					<td>上传图片</td>
					<td>
		                <input id="file1" type="file" multiple="true">
		                <span>类型: *.jpg,*.png,*.gif 大小: 2000KB 数量: 10</span>
		                <script type="text/javascript">
		                    $(function() {
		                        $('#file1').uploadify({
		                            'formData'     : {//POST数据
		                                '<?php echo session_name();?>' : '<?php echo session_id();?>',
		                            },
		                            'fileTypeDesc' : '上传文件',//上传描述
		                            'fileTypeExts' : '*.jpg;*.png;*.gif',//上传允许的类型
		                            'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',//上传的flash
		                            'uploader' : '{{U('uploadMore')}}',//上传调用的方法
		                            'buttonText':'选择文件',
		                            'fileSizeLimit' : '2000KB',//上传文件的大小
		                            'uploadLimit' : 10,//上传文件数
		                            'width':65,
		                            'height':25,
		                            'successTimeout':10,//等待服务器响应时间
		                            'removeTimeout' : 0.2,//成功显示时间
		                            'onUploadSuccess' : function(file, data, response) {
		                                //转为json
		                                data=$.parseJSON(data);
		                                //获得图片地址
		                                var imageUrl = data.url;
		                                var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='album[]' value='"+data.path+"'/></li>";
		                                $("#uploadList1 ul").prepend(li);
		                            }
		                        });
		                    });
		                </script>
					</td>
				</tr>
			</table>
				<!-- 异步上传后图片显示的位置 -->
                <div id="uploadList1">
                    <ul>
						{{foreach from="$album" value="$v"}}
							<li>
								<img src="{{$v}}" alt=""><a class="dell" href="javascript:;">X</a>
								<input type="hidden" value="{{$v}}" name="album[]">
							</li>
						{{endforeach}}
                    </ul>
                </div>
			</div>
			<span class="btn btn-info">商品详细</span>
			<div class="form-group">
				<script id="editor" type="text/plain" style="width:100%;height:300px;" name="content">{{$gddata['goods_detail']}}</script>
				<script>
					var ue = UE.getEditor('editor');
				</script>
			</div>
			<span class="btn btn-info">商品简述</span>
			<table class='table table-bordered'>
				<tr  class="info">
					<td>
						<textarea name="goods_info" id="" style="width:80%;height:100px;">{{$gddata['goods_info']}}</textarea>
					</td>
				</tr>
			</table>
			<span class="btn btn-info">售后服务</span>
			<table class='table table-bordered'>
				<tr  class="info">
					<td>
						<textarea name="intro" style="width:80%; height:99px;">{{$gddata['after_sale']}}</textarea>
					</td>
				</tr>
			</table>
			<input type="hidden" name="id" value="{{$_SESSION['id']}}">
			<input type="submit" value="编辑商品" class="btn btn-primary btn-block btn-large"/>
		</form>
		</div>
	</body>
</html>
